<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head lang="en">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no"/>
    <meta name="format-detection" content="telephone=no"/>
    <meta name="format-detection" content="email=no"/>
    <meta charset="UTF-8">
    <script type="text/javascript" th:src="@{${session.baseUrl}+'js/common.js'}"></script>
    <script th:src="@{${session.baseUrl}+'js/jquery.js'}"></script>
    <link th:href="@{${session.baseUrl}+'style/reset.css'}" rel="stylesheet" type="text/css">
    <link th:href="@{${session.baseUrl}+'style/base.css'}" rel="stylesheet" type="text/css">
    <link th:href="@{${session.baseUrl}+'style/header.css'}" rel="stylesheet" type="text/css">
    <link rel="stylesheet" th:href="@{${session.baseUrl}+'style/register.css'}"/>
    <link rel="stylesheet" th:href="@{${session.baseUrl}+'style/myProject.css'}"/>
    <link th:href="@{${session.baseUrl}+'style/dialog.css'}" rel="stylesheet" type="text/css">
    <link th:href="@{${session.baseUrl}+'style/global.css'}" rel="stylesheet" type="text/css">
    <script th:src="@{${session.baseUrl}+'js/dialog.js'}"></script>
    <title>企业注册</title>
    <style>
        .sub{
            margin-left: 0.3rem;
            margin-right: 0.3rem;
            line-height: 0.75rem;
            width: 6.3rem;
            border-radius: 0.1rem;
            height: 0.75rem;
            font-size: 0.26rem;
            background: #2d9cff;
            color: #fff;
            margin-top: 0.1rem;
        }
    </style>
</head>
<body>
<header><span onclick="javascript:history.go(-1)"></span>企业注册</header>
<nav>
    <ul class="df jcsb bgwh">

        <li class="tc fx1 active">手机验证</li>
       <!-- <li class="tc fx1 "><a th:href="@{/wap/businessregist.html/(openid=${openid})}" style="text-decoration:none;color:#101010;">邮箱验证</a></li>-->
    </ul>
</nav>
<form action="" id="form1" method="post">
    <ul class="form">
        <input type="hidden" id="num">
        <input type="hidden" name="infoI" value="1">
        <input type="hidden" name="openId" th:value="${openid}">
        <li><input name="phone" id="phone" type="text" placeholder="请输入手机号" onblur="phoneyanzheng()"/></li>
        <li><input id="inputNum1" type="text" placeholder="请输入手机验证码" onblur="yanphoneNum()"/><span id="confirm1">获取验证码</span></li>
        <li><input name="infoV" id="mail" type="text" placeholder="请输入邮箱" onblur="youxiang()"/></li>
        <input name="name" id="userName" type="hidden"/>
        <li><input name="businessName" id="businessName" type="text" placeholder="请输入企业名称" onblur="yanzhengbusinessname()"/></li>
        <li><input  id="password1" type="password" placeholder="请输入密码" onblur="pass1()"/></li>
        <li><input name="password" id="rePassword" type="password" placeholder="请确认密码" onblur="pass2()"/></li>
        <li>
            <input type="hidden" th:value="${basicTable.userRegistration}" id="userRegistration"/>
            <span th:if="${basicTable.userRegistration == 0}"><input th:value="${inviteCode}==null?'':${inviteCode}" name="inviteCode" id="inviteCode" type="text" autocomplete="off"  placeholder="请输入邀请码" onblur="yaninviteCode()"/></span>
            <span th:if="${basicTable.userRegistration == 1}"><input th:value="${inviteCode}==null?'':${inviteCode}" name="inviteCode" id="inviteCode1" type="text" autocomplete="off" placeholder="请输入邀请码"/></span>
        </li>
        <li><input name="protocol" id="protocol" type="checkbox" value="" onclick="xieyi()">
            我同意《<a href="javascript:void(0)" th:href="@{/wap/InformationAbout/xieyi.html}">网站注册协议</a>》
            <span id="protocolAlt" data-info="请查看协议">请查看协议</span></li>
        <li><span id="span" style="font-size: 0.3rem;margin-left: 0.2rem"></span></li>
        <li><input type="button" class="sub" value="注&nbsp;&nbsp;&nbsp;&nbsp;册" onclick="regist()"/></li>
    </ul>
</form>



</body>
<script type="text/javascript" th:inline="javascript">
    var basePath = /*[[${#httpServletRequest.getScheme() + "://" + #httpServletRequest.getServerName() + ":" + #httpServletRequest.getServerPort() + #httpServletRequest.getContextPath()}]]*/;

    var reg=$("#userRegistration").val();
    function regist() {

        if (ma==2) {
            $("#span").html('邮箱不能为空').css('color', '#ff2525');
        }else if(ma==3){
            $("#span").html('邮箱格式错误').css('color', '#ff2525');
        }else if(ma==4){
            $("#span").html('邮箱已被注册').css('color', '#ff2525');
        }else if(manum==2){
            $("#span").html('验证码不能为空').css('color', '#ff2525');
        }else if(manum==3){
            $("#span").html('验证码不正确').css('color', '#ff2525');
        }else if(manum1==2){
            $("#span").html('企业名称不能为空').css('color', '#ff2525');
        }else if(manum1==3){
            $("#span").html('企业名称格式不正确').css('color', '#ff2525');
        }else if(manum1==4){
            $("#span").html('企业名称长度必须大于4位').css('color', '#ff2525');
        }else if(phonenum==2){
            $("#span").html('手机号不能为空').css('color', '#ff2525');
        }else if(phonenum==3){
            $("#span").html('手机号格式错误').css('color', '#ff2525');
        }else if(phonenum==4){
            $("#span").html('手机号已被注册').css('color', '#ff2525');
        }else if(passnum==2){
            $("#span").html('密码不能为空').css('color', '#ff2525');
        }else if(passnum==3){
            $("#span").html('两次输入密码不一致').css('color', '#ff2525');
        }else if(xy==2){
            $("#span").html('请阅读协议').css('color', '#ff2525');
        }else if(reg==0){
            if(yaonum==2){
                $("#span").html('请输入邀请码').css('color', '#ff2525');
            }else if(ma==1&&manum==1&&phonenum==1&&passnum==1&&xy==1&&yaonum==1){
                $.ajax({
                    //几个参数需要注意一下
                    type: "POST",//方法类型
                    dataType: "json",//预期服务器返回的数据类型
                    url: basePath+'/wap/memberUser/regist' ,//url
                    data:$('#form1').serialize(),
                    success: function (result) {
                        if (result.msg == "success") {
                            $('body').dailog({type: 'success', title: '注册', discription: '注册成功'});
                            self.setInterval(function () {
                                window.location.href=basePath+"/wap/mine.html";
                            }, 2000)
                        }else {
                            $('body').dailog({type: 'warning',title: '注册', discription: '注册失败'});
                            self.setInterval(function () {
                                window.location.href=basePath+"/wap/index.html";
                            }, 2000)
                        };
                    },
                    error : function() {
                        alert("异常！");
                    }
                });
            }
        }else if(reg==1){
            if(ma==1&&manum==1&&phonenum==1&&passnum==1&&xy==1){
                $.ajax({
                    //几个参数需要注意一下
                    type: "POST",//方法类型
                    dataType: "json",//预期服务器返回的数据类型
                    url: basePath+'/wap/memberUser/regist' ,//url
                    data:$('#form1').serialize(),
                    success: function (result) {
                        if (result.msg == "success") {
                            $('body').dailog({type: 'success', title: '注册', discription: '注册成功'});
                            self.setInterval(function () {
                                window.location.href=basePath+"/wap/mine.html";
                            }, 2000)
                        }else {
                            $('body').dailog({type: 'warning',title: '注册', discription: '注册失败'});
                            self.setInterval(function () {
                                window.location.href=basePath+"/wap/index.html";
                            }, 2000)
                        };
                    },
                    error : function() {
                        alert("异常！");
                    }
                });
            }
        }
    }

    //发送短信
    $("#confirm1").one('click',function(){

        var phone = $("#phone").val();
        var num = $("#num");
        var span = $("#span");
        $("#userName").val(phone);
        $.ajax({
                url: basePath + '/memberSendSms/sms',
                type: "get",
                dataType: "JSON",
                data: {
                    PhoneNumbers: phone,
                    TemplateCode:"SMS_171358593",
                },
                contentType: 'application/json;charset=UTF-8',
                //async: false,
                success: function (e) {
                    if (e.msg == "OK"){
                        span.html('发送成功').css('color', '#33FF00');
                        num.val(e.data);
                    }else {
                        span.html('发送失败').css('color', '#ff2525');
                    }
                }
            }
        )

    });
    //邀请码验证
    var yaonum=2;
    function yaninviteCode() {
        var namespan = $("#span");
        var sign = $("#userRegistration").val();
        var inviteCode = $("#inviteCode").val();
        if (sign == 0){
            if(inviteCode!=null&&inviteCode!=''){
                $.ajax({
                        url: basePath + '/memberUser/isInviteCode',
                        type: "get",
                        dataType: "JSON",
                        data: {
                            inviteCode:inviteCode
                        },
                        contentType: 'application/json;charset=UTF-8',
                        //async: false,
                        success: function (data) {
                            if (data.msg == "ok") { //
                                namespan.html(' ');
                                yaonum=1;
                            }
                        }
                    }
                )
            }
            if (inviteCode == "" || inviteCode != inviteCode){
                namespan.html('请输入邀请码').css('color', '#ff2525');
                yaonum=2;
            } else {
                namespan.html('');
                yaonum=1;
            }
        }
    }
    var manum=2;
    /*手机验证码输入验证*/
    function yanphoneNum() {
        var inputNum1 = $('#inputNum1').val();
        var num = $('#num').val();
        var namespan = $('#span')
        if (num != inputNum1) {
            namespan.html('验证码不正确').css('color', '#ff2525');
            manum=3;
        } else if (inputNum1 == "") {
            namespan.html('验证码不能为空').css('color', '#ff2525');
            manum=2;
        } else {
            namespan.html(' ');
            manum=1;
        }
    }
    //企业名称验证
    var manum1=2;
    function yanzhengbusinessname() {
        var namespan = $("#span");
        var x = document.getElementById("businessName").value.length;
        var name = $("#businessName").val();
        var myReg = /^[\u4e00-\u9fa5_a-zA-Z0-9_]{4,20}$/;
        if (name == "") {
            namespan.html('请输入企业名称').css('color', '#ff2525');
            manum1 =2;
        } else if (x < 4) {
            namespan.html('企业名称长度必须大于4位').css('color', '#ff2525');
            manum1 =4;
        }else if (!myReg.test(name)) {
            namespan.html('格式不正确').css('color', '#ff2525');
            manum1 =3;
        } else {
            namespan.html(' ');
            manum1=1;
        }
    }



    //邮箱验证
    function sendmail() {
        var mail = $("#mail").val();
        var num = $("#num");
        $.ajax({
                url: basePath + '/memberSendMail/send',
                type: "get",
                dataType: "JSON",
                data: {
                    accept: mail,
                    type:'企业注册',
                    text:'您正在注册企业帐号，您的验证码是：'
                },
                contentType: 'application/json;charset=UTF-8',
                //async: false,
                success: function (data) {

                    if (data != null) {
                        num.val(data);

                    }

                }
            }
        )
    }

    var manum=2;
    /*验证码输入验证*/
    function yanMailNum() {
        var inputNum = $('#inputNum').val();
        var num = $('#num').val();
        var namespan = $('#span')
        if (num != inputNum) {
            namespan.html('验证码不正确').css('color', '#ff2525');
            manum=3;
        } else if (inputNum == "") {
            namespan.html('验证码不能为空').css('color', '#ff2525');
            manum=2;
        } else {
            namespan.html(' ');
            manum=1;
        }
    }


    //密码验证
    function pass1() {
        var namespan = $("#span");
        var x = document.getElementById("password1").value.length;
        var name = $("#password1").val();
        if (name == '') {
            namespan.html('请输入密码').css('color', '#ff2525');
            return false;
        } else if (x <= 7) {
            namespan.html('密码必须大于8位').css('color', '#ff2525');
            return false;
        } else {
            namespan.html(' ');
            return true;
        }
    }

    var passnum=2;
    //确认密码验证
    function pass2() {
        var namespan = $("#span");
        var pass1 = $("#password1").val();
        var pass2 = $("#rePassword").val();
        if (pass2 == '') {
            namespan.html('请输入密码').css('color', '#ff2525');
            passnum=2;
        } else if (pass1 == pass2) {
            namespan.html(' ');
            passnum=1;
        } else {
            namespan.html('两次输入密码不一致').css('color', '#ff2525');
            passnum=3;
        }
    }

    var phonenum=2;
    //手机号码验证
    function phoneyanzheng() {
        var namespan = $("#span");
        var phone = $("#phone").val();
        if (phone == '') {
            namespan.html('手机号不能为空').css('color', '#ff2525');
            phonenum=2;
        } else if (!(/^1[3456789]\d{9}$/.test(phone))) {
            namespan.html('手机号格式不正确').css('color', '#ff2525');
            phonenum=3;
        } else {
            var phone1 = $("#phone").val();
            $.ajax({
                url: basePath + '/memberUser/isPhone',
                type: "get",
                dataType: "JSON",
                data: {
                    phone: phone1,
                },
                contentType: 'application/json;charset=UTF-8',
                //async: false,
                success: function (data) {
                    if (data.msg == "no") { //
                        namespan.html('手机号已注册').css('color', '#ff2525');
                        document.getElementById('phone').innerHTML = '';
                        phonenum=4;
                    } else if (data.msg == "ok") {
                        namespan.html(' ');
                        phonenum=1;
                    }
                },
                error: function () {
                }
            });
        }

    }

 /*   var namenum=2;
    //用户名验证
    function yanzhengname() {
        var namespan = $("#span");
        var x = document.getElementById("userName").value.length;
        var name = $("#userName").val();
        var myReg = /^[A-Za-z][A-Za-z0-9]{5,11}$/;
        if (name == '') {
            namespan.html('请输入用户名,6-12位').css('color', '#ff2525');
            namenum=2;
        } else if (x <= 5) {
            namespan.html('用户名必须大于6位').css('color', '#ff2525');
            namenum=3;
        }else {
            var name1 = $("#userName").val();
            $.ajax({
                url: basePath + '/memberUser/isName',
                type: "get",
                dataType: "JSON",
                data: {
                    name: name1,
                },
                contentType: 'application/json;charset=UTF-8',
                //async: false,
                success: function (data) {
                    if (data.msg == "no") { //
                        namespan.html('用户名已注册').css('color', '#ff2525');
                        document.getElementById('phone').innerHTML = '';
                        namenum=4;
                    } else if (data.msg == "ok") {
                        namespan.html(' ');
                        namenum=1;
                    }
                },
            });
        }
    }
*/

    var ma=2;
    //邮箱格式验证
    function youxiang() {
        var namespan = $("#span");
        var mail = $("#mail").val();
        var myReg = /^[a-zA-Z0-9_-]+@([a-zA-Z0-9]+\.)+(com|cn|net|org)$/;
        if (mail == '') {
            namespan.html('请输入邮箱').css('color', '#ff2525');
            ma=2;
        } else if (!myReg.test(mail)) {
            namespan.html('邮箱格式不对').css('color', '#ff2525');
            ma=3;
        } else {
            var mail = $("#mail").val();
            $.ajax({
                url: basePath + '/memberUser/isMail',
                type: "get",
                dataType: "JSON",
                data: {
                    mail: mail,
                },
                contentType: 'application/json;charset=UTF-8',
                //async: false,
                success: function (data) {
                    if (data.msg == "no") { //
                        namespan.html('此邮箱已被注册,请更换邮箱').css('color', '#ff2525');
                        document.getElementById('phone').innerHTML = '';
                        ma=4;
                    } else if (data.msg == "ok") {
                        namespan.html(' ');
                        ma=1;
                    }
                },
            });
        }

    }
    var xy=2;
    function xieyi() {
        var namespan = $("#span");
        if ($("#protocol").prop("checked")) {
            namespan.html(' ');
            xy=1;
        }else if(!$("#protocol").prop("checked")) {
            namespan.html('请阅读协议').css('color', '#ff2525');
            xy=2;
        }
    }


</script>

</html>